package com.taotao.sys.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.google.common.base.Preconditions;
import com.taotao.sys.mapper.SysFuncMapper;
import com.taotao.sys.model.po.SysFunc;
import com.taotao.sys.service.SysFuncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 * 系统功能服务接口实现类
 * </p>
 *
 * @author Fan Beibei
 * @version V1.0
 * @since 2023-04-08 19:57:22
 */
@Slf4j
@Service
public class SysFuncServiceImpl implements SysFuncService {
    @Resource
    private SysFuncMapper sysFuncMapper;


    @Override
    public PageInfo<SysFunc> queryByPage(SysFunc param, int pageNum, int pageSize) {
        Preconditions.checkArgument(pageNum > 0);
        Preconditions.checkArgument(pageSize > 0);

        Page<SysFunc> page = sysFuncMapper.selectByPage(param, pageNum, pageSize);

        return new PageInfo<>(page);
    }


//------------以上是生成代码-----------------------------------------------------------------------------------------------------------------

    @Override
    public Set<String> queryFuncCodeByRoleIds(Collection<Long> roleIds) {
        Preconditions.checkArgument(!CollectionUtils.isEmpty(roleIds));

        List<SysFunc> funcList = sysFuncMapper.selectByRoleIds(roleIds);
        if (CollectionUtils.isEmpty(funcList)) {
            return null;
        }

        return funcList.stream().map(SysFunc::getCode).collect(Collectors.toSet());
    }


}
